<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *评论管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['name'])){
		$params['title like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_shoufrom_comment',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['title']=pdo_getcolumn('jy_shoufrom_list',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['pid']),'title');
			//员工姓名
			$item['name']=pdo_getcolumn('jy_wxshifu_member',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['worker_id']),'title');
			$item['order']=pdo_get('jy_shoufrom_order',array('id'=>$item['order_id'],'uniacid'=>$_SESSION['uniacid']),array('username','mobile','address'));
			$item['address']=$item['order']['address'];
			$item['username']=$item['order']['username'];
			$item['mobile']=$item['order']['mobile'];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'评论列表'),
		),
		'list'=>array('data'=>'list','edit'=>true,'list'=>array(
			array('name'=>'title','title'=>'项目名称','type'=>'string'),
			array('name'=>'star','title'=>'评分','type'=>'star'),
			array('name'=>'order_id','title'=>'订单ID','type'=>'string'),
			array('type'=>'string_more','title'=>'客户信息','data'=>array(
				array('title'=>'姓名：','name'=>'username'),
				array('title'=>'电话：','name'=>'mobile'),
				array('title'=>'地址：','name'=>'address')
				)
			),
			array('name'=>'name','title'=>'员工姓名','type'=>'string'),
			array('name'=>'msg','title'=>'评论内容','type'=>'string'),
			array('name'=>'show','title'=>'显示?','type'=>'switch','set'=>'set'),
		)),
		'search'=>array(
			array('name'=>'title','width'=>15,'title'=>'项目名称','type'=>'string'),
			array('name'=>'name','width'=>15,'title'=>'员工姓名','type'=>'string'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_shoufrom_comment',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		
	}else{
		$item=array();
	}
	$item['images']=json_decode($item['images'],true);
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'评价',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回评价列表'),
		),
		'edit'=>array(
			array('name'=>'star','title'=>'星数','type'=>'radio','options'=>'star'),
			array('name'=>'msg','title'=>'评论内容','type'=>'text'),
			array('name'=>'images','title'=>'图片','type'=>'images'),
			array('name'=>'show','title'=>'显示?','type'=>'switch','set'=>'set'),
		)
	);
	$return['star']=array(1=>'1星',2=>'2星',3=>'3星',4=>'4星',5=>'5星');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'star'=>trim($postdata['star']),
		'msg'=>trim($postdata['msg']),
		'images'=>ijson_encode($postdata['images']),
		'show'=>intval($postdata['show']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_shoufrom_comment',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('修改成功！','','list');
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_shoufrom_comment',$data);
		exi('增加成功！','','list');
	}
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择评论！','error');
	}
	$update=array();
	$post=get_postdata();
	if(isset($post['show'])){
		$update['show']=intval($post['show']);
	}
	if($update){
		$this->pdo_update('comment',$update,array('id'=>$id));
	}
	exi('操作成功！');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_shoufrom_comment',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}